package com.neusoft.dibuy.tyut.net.server;

import com.neusoft.dibuy.tyut.net.cfg.NetConfig;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class DemoApp {



    public static void main(String[] args) throws IOException {
//        打开端口，进行侦听
        ServerSocket serverSocket = new ServerSocket(NetConfig.MSG_PORT);
        System.out.println(1);
//        侦听到，建立连接，进行通信
        System.out.println("2.........");
        Socket socket = serverSocket.accept();
        System.out.println(3);
//        通信
        InputStream is = socket.getInputStream();
        byte[] bs = new byte[NetConfig.MSG_LENGTH];
        is.read(bs);
        String msg = new String(bs);
        System.out.printf(msg);

        is.close();
        socket.close();
        serverSocket.close();
        System.out.println("Hello world!");
    }
}
